package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.SameListModel;
import com.jiayang.hhotel.listener.OnAdapterButtonListener;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/5/16 0016.
 * pgetcodelist列表适配器
 */

public class SameListAdapter extends SwipeMenuAdapter<SameListAdapter.ViewHolder> {

//    private static final int TYPE_ITEM =0; //普通Item View
//    private static final int TYPE_FOOTER = 1; // 底部FootView

    private Context t;
    private List<SameListModel.CceDtoListBean> mList;
    private OnAdapterButtonListener listener;

    public SameListAdapter(Context context, List<SameListModel.CceDtoListBean> list,OnAdapterButtonListener listener){
        this.mList=list;
        this.t=context;
        this.listener = listener;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final SameListModel.CceDtoListBean model = mList.get(position);
        holder.one.setText(t.getString(R.string.chinese_descripe));
        holder.two.setText(t.getString(R.string.english_descripe));
        holder.three.setText(t.getString(R.string.code));
        holder.name.setText(model.getChnDescp());
        holder.department.setText(model.getEngDescp());
        holder.canUse.setText(model.getCode());
        holder.click.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(listener != null){
                    listener.OnAdapterButtonClick(model);
                }
            }
        });
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(t).inflate(R.layout.contact_person_list_item, parent, false);
    }

    @Override
    public ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new ViewHolder(realContentView);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        LinearLayout click;
        TextView one;//第一行标题
        TextView two;//第二行标题
        TextView three;//第三行标题

        TextView name;//中文描述
        TextView department;//英文描述
        TextView canUse;//值

        public ViewHolder(View convertView) {
            super(convertView);
            click = (LinearLayout) convertView.findViewById(R.id.ll_click);
            one = (TextView) convertView.findViewById(R.id.tv_one);
            two = (TextView) convertView.findViewById(R.id.tv_two);
            three = (TextView) convertView.findViewById(R.id.tv_three);

            name= (TextView) convertView.findViewById(R.id.tv_name);
            department= (TextView) convertView.findViewById(R.id.tv_department);
            canUse= (TextView) convertView.findViewById(R.id.tv_can_use);
        }
    }
}
